import { takeEvery, put } from "redux-saga/effects"
import { INI_LIST, getInitListActionWithSaga } from "./actionCreators"
import axios from 'axios'

function* getInitList() {
  const res = yield axios.get("/api/todolist.json")
  const action = getInitListActionWithSaga(res.data)
  yield put(action)
}

// generator 函数用于捕获
function* todoSaga() {
  // 使用 takeEvery 捕捉 action
  yield takeEvery(INI_LIST, getInitList)
}

export default todoSaga
